package com.pan.admin.module.distribute.controller;


import com.pan.admin.common.annotation.Log;
import com.pan.admin.common.core.controller.BaseController;
import com.pan.admin.common.core.domain.AjaxResult;
import com.pan.admin.common.core.page.TableDataInfo;
import com.pan.admin.common.enums.BusinessType;
import com.pan.admin.common.utils.poi.ExcelUtil;
import com.pan.admin.module.distribute.entity.LoanDistribute;
import com.pan.admin.module.distribute.service.LoanDistributeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 智能分配子链接Controller
 *
 * @author ts
 * @date 2023-09-10
 */
@RestController
@RequestMapping("/distribute")
public class LoanDistributeController extends BaseController {
    @Autowired
    private LoanDistributeService loanDistributeService;

    /**
     * 查询智能分配子链接列表
     */
    @PreAuthorize("@ss.hasPermi('distribute:list')")
    @GetMapping("/list")
    public TableDataInfo list(LoanDistribute loanDistribute) {
        startPage();
        List<LoanDistribute> list = loanDistributeService.list(loanDistribute);
        return getDataTable(list);
    }

    /**
     * 导出智能分配子链接列表
     */
    @PreAuthorize("@ss.hasPermi('distribute:export')")
    @Log(title = "智能分配子链接", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LoanDistribute loanDistribute) {
        List<LoanDistribute> list = loanDistributeService.list(loanDistribute);
        ExcelUtil<LoanDistribute> util = new ExcelUtil<LoanDistribute>(LoanDistribute.class);
        util.exportExcel(response, list, "智能分配子链接数据");
    }

    /**
     * 获取智能分配子链接详细信息
     */
    @PreAuthorize("@ss.hasPermi('distribute:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(loanDistributeService.getById(id));
    }

    /**
     * 新增智能分配子链接
     */
    @PreAuthorize("@ss.hasPermi('distribute:add')")
    @Log(title = "智能分配子链接", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LoanDistribute loanDistribute) {
        return toAjax(loanDistributeService.insertLoanDistribute(loanDistribute));
    }

    /**
     * 修改智能分配子链接
     */
    @PreAuthorize("@ss.hasPermi('distribute:edit')")
    @Log(title = "智能分配子链接", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LoanDistribute loanDistribute) {
        return toAjax(loanDistributeService.updateLoanDistribute(loanDistribute));
    }

    /**
     * 删除智能分配子链接
     */
    @PreAuthorize("@ss.hasPermi('distribute:remove')")
    @Log(title = "智能分配子链接", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(loanDistributeService.batchDeleteById(ids));
    }
}
